package com.zhongkai.controller;

import com.zhongkai.app.service.SellService;
import com.zhongkai.app.service.SetmodelService;
import com.zhongkai.model.utils.TTHelp;
import com.zhongkai.model.utils.ZhongkaiResult;
import com.zhongkai.model3.Chinaset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 销售新增
 * */
@Controller
public class SellController {

    @Autowired
    private SellService sellService;



    @Autowired
    private SetmodelService setmodelService;
    /**
     * 销售添加
     *
     * @param set_uuid    产品编号
     * @param sell_name   产品名称
     * @param sell_price  单价
     * @param sell_count  数量
     * @param sell_sum    总价
     * @param sell_client 客户姓名
     * @param sell_number 合同编号
     */
    @RequestMapping(value = "/sell/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addSell( String set_uuid, String sell_name, String sell_price,
                                  String sell_count, String sell_sum, String sell_client, String sell_number,
                                  HttpServletRequest httpServletRequest
    ) {


        String uuid = TTHelp.generate();
        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = sellService.addSell(uuid,set_uuid,
                sell_name,sell_price,sell_count,sell_sum,sell_client,sell_number,chinaset.getSetName(),chinaset.getUuid());

        return result;
    }




    /**
     * 销售修改
     *
     * @param sell_uuid   订单编号
     * @param set_uuid    产品编号
     * @param sell_name   产品名称
     * @param sell_price  单价
     * @param sell_count  数量
     * @param sell_sum    总价
     * @param sell_client 客户姓名
     * @param sell_number 合同编号
     */
    @RequestMapping(value = "/sell/update", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateSell( String sell_uuid, String set_uuid, String sell_name, String sell_price, String sell_count, String sell_sum, String sell_client, String sell_number
    ) {


        ZhongkaiResult result = sellService.updateSell(sell_uuid,set_uuid,
                sell_name,sell_price,sell_count,sell_sum,sell_client,sell_number);

        return result;
    }



    /**
     * 删除订单
     *
     * @param sell_uuid   订单编号
     */
    @RequestMapping(value = "/sell/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeSell( String sell_uuid
    ) {


        ZhongkaiResult result = sellService.removeSell(sell_uuid);

        return result;
    }


    /**
     * 订单列表
     * @param page 页码
     * @param rows 条数
     */
    @RequestMapping(value = "/sell/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listSell(@RequestParam(defaultValue = "0")Integer page, @RequestParam(defaultValue = "0")Integer rows
    ) {


        ZhongkaiResult result = sellService.listSell(page,rows);

        return result;
    }



    /**
     * 公司产品列表
     * @param page 页数
     * @param rows 每页数据数量
     */
    @RequestMapping(value = "/set_model/list_sell", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult model_list(@RequestParam(defaultValue = "0")Integer page, @RequestParam(defaultValue = "0")Integer rows) {

        ZhongkaiResult result = setmodelService.getModelList(page,rows);

        return result;
    }

}
